<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>通知设定管理</title>
    <s:head/>
</head>
<script type="text/javascript">

    var processes = new Array();
    $.ajax({
        url: "process-listProcess?process.bizType=${sysMsgSetting.process.bizType}",
        method: "post",
        async: false,
        success: function (data) {
            $.each(data.processes, function (index, element) {
                var processOption = new Array();
                processOption.push(element.processName);
                processOption.push(element.processId);
                processes.push(processOption);
            });
        }
    });

    var msgSettingState = $.mrdForm.ajaxdp("dropdown-useState");

    var formSetting = {
        title: "通知设定管理",
        module: 'save',
        numCount: 2,
        columns: [
            {
                name: "sysMsgSetting.process.processId",
                label: "业务流程名称",
                width: 10,
                type: "dropdown",
                validate: "validate[required]",
                data: processes
            }, {
                name: "sysMsgSetting.useState",
                label: "通知设定状态",
                type: "dropdown",
                minLength: 0,
                data: msgSettingState,
                validate: "validate[required]"
            }, {
                name: "sysMsgSetting.remarks",
                label: "通知设定备注",
                type: "textarea"
            }, {
                name: "sysMsgSetting.id",
                hidden: true
            }
        ],
        buttons: {
            query: false,
            custom: [
                {
                    value: "返回",
                    click: function () {
                        history.back();
                    }
                }
            ]
        },
        form: {
            'url': "msgSetting-saveOrUpdateSysMsgSetting",
            'data': function () {
                var id = "${sysMsgSetting.id}";
                if (id) {
                    var dataValue = new Object();
                    $.ajax({
                        url: "msgSetting-getData?sysMsgSetting.id=" + id,
                        method: "post",
                        async: false,
                        success: function (data) {
                            $.each(msgSettingState, function (i, n) {
                                if (data.sysMsgSetting.useState == n[1]) {
                                    var dropdownName = $.mrdForm.getDropDwonLabelName("sysMsgSetting.useState");
                                    data[dropdownName] = n[0];
                                }
                            });
                            $.each(processes, function (index, element) {
                                if (data.sysMsgSetting.process.processId == element[1]) {
                                    var dropdownName = $.mrdForm.getDropDwonLabelName("sysMsgSetting.process.processId");
                                    data[dropdownName] = element[0];
                                }
                            });
                            dataValue = data;
                        }
                    });
                    return dataValue;
                }
            },
            'ajaxForm': {
                success: function (data) {
                    alert(data.msg);
                }
            }
        }
    };

    $(document).ready(function () {
        //初始化表单验证引擎
        $("#userForm").validationEngine("attach", {
            //消息位置
            promptPosition: "bottomRight",
            scroll: false
        });
        //初始化ajaxForm参数
        var options = {
            //提交方式
            type: "POST",
            //提交数据格式
            dataType: "json",
            //在提交之前做的操作
            beforeSubmit: function () {
                return $("#userForm").validationEngine("validate");
            },
            //成功后做的操作
            success: function (responseText, statusText, xhr, $form) {
                alert(responseText.msg);
                location.href = "msgSetting-find?process.bizType=" + $("#bizType").val();
            }
        };
        $('#userForm').ajaxForm(options);
        $("#userForm").mrdForm(formSetting);
    });
    function submitTheForm() {
        $("#userForm").submit();
    }
</script>
<body>
<form id="userForm"></form>
</body>
</html>
